package ranks.types;

import java.util.HashMap;
import java.util.Map;

public class Position {

	private static Map<String, Position> positionMap
		= new HashMap<String, Position>();
	
	public static Position QB = new Position("QB", "Quarterback");
	public static Position RB = new Position("RB", "Running Back");
	public static Position WR = new Position("WR", "Wide Receiver");
	public static Position TE = new Position("TE", "Tight End");
	public static Position DEF = new Position("DEF", "D/ST", "Defense/Special Teams");
	public static Position K = new Position("K", "Kicker");
	public static Position DL = new Position("DL", "Defensive Lineman");
	public static Position LB = new Position("LB", "Linebacker");
	public static Position DB = new Position("DB", "Defensive Back");
	
	private String positionID;
	private String altPositionID;
	private String positionName;
	
	private Position(String positionID, String positionName) {
		this(positionID, positionID, positionName);
	}
	
	private Position(String positionID, String altPositionID, String positionName) {
		this.positionID = positionID;
		this.altPositionID = altPositionID;
		this.positionName = positionName;
		
		Position.positionMap.put(this.positionID, this);
	}
	
	public static Position getPosition(String positionID) {
		Position position = Position.positionMap.get(positionID);
		
		if(position == null) {
			position = Position.getPositionByAltID(positionID);
		}
		
		return position;
	}
	
	private static Position getPositionByAltID(String positionID) {
		Position position = null;
		
		for(Position checkPosition : Position.positionMap.values()) {
			if(positionID.equals(checkPosition.getAltPositionID())) {
				position = checkPosition;
			}
		}
		
		return position;
	}
	
	public String getPositionID() {
		return this.positionID;
	}
	
	public String getAltPositionID() {
		return this.altPositionID;
	}
	
	public String getPositionName() {
		return this.positionName;
	}
	
}
